package com.wangxl.rabbitmqdemo.conf;

import com.wangxl.rabbitmqdemo.enumtype.RoutingKeyEnum;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 业务MQ配置
 * @Author: wangxl
 * @Date: 2019/3/23 10:50
 */
@Configuration(value = "businessMQConfig")
public class BusinessMQConfig {

    /**
     * 声明一个业务消息的队列
     * @return
     */
    @Bean("messageQueue")
    Queue getMessageQueue(){
        return new Queue("messageQueue",true);
    }
    /**
     * 声明一个业务消息的队列
     * @return
     */
    @Bean("emailQueue")
    Queue getEmailQueue(){
        return new Queue("emailQueue",true);
    }

    /**
     * 声明一个businessExchange
     * @return
     */
    @Bean("businessExchange")
    DirectExchange getDirectExchange(){
        return new DirectExchange("businessExchange");
    }

    /**
     * 声明一个Binding，businessExchange----------》messageQueue
     * @return
     */
    @Bean("messageBinding")
    Binding getMessageBinding(){
        return BindingBuilder.bind(getMessageQueue()).to(getDirectExchange()).with(RoutingKeyEnum.MESSAGE.getRoutingKey());
    }
    /**
     * 声明一个Binding，businessExchange----------》emailQueue
     * @return
     */
    @Bean("emailBinding")
    Binding getEmailBinding(){
        return BindingBuilder.bind(getEmailQueue()).to(getDirectExchange()).with(RoutingKeyEnum.EMAIL.getRoutingKey());
    }


}
